<template>
	<view class="shopModelAll">
		<view class="shopModelAll-list">
			<view class="shopModelAll-li" v-for="(item, index) of list" :key="index">
				<view class="shopModelAll-li-left">
					<image class="shopModelAll-li-left-img" @click="previewImage(item.attributeLogo)" :src=item.attributeLogo mode=""></image>
				</view>
				<view class="shopModelAll-li-right">
					<view class="shopModelAll-li-right-title font_blod">
						{{item.attributeName}}
					</view>
					<view class="shopModelAll-li-right-id">
						ID:{{item.id}}
					</view>
					<view class="shopModelAll-li-right-btm">
						<view class="shopModelAll-li-right-btm-left">
							<text class="shopModelAll-li-right-btm-left-txt1">￥</text>
							<text class="shopModelAll-li-right-btm-left-txt2">{{item.attributeSalePrice}}</text>
							<text class="shopModelAll-li-right-btm-left-txt3">/{{item.partsUnit}}</text>
						</view>
						<view class="shopModelAll-li-right-btm-right">
							<view class="shopModelAll-li-right-btm-right-bj font_blod" @click="cli_edit(item)">
								编辑
							</view>
							<view @click="cli_j(item)" class="shopModelAll-li-right-btm-right-ljsj font_blod" v-if="item.isShow == 0">
								立即上架
							</view>
							<view @click="cli_j(item)" class="shopModelAll-li-right-btm-right-ljsj font_blod" v-if="item.isShow == 1">
								立即下架
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				id: "998658606058442752",
				list: []
			}
		},
		onLoad(val) {
			if (val.id) {
				this.id = val.id
			}
		},
		mounted() {
			
		},
		onShow() {
			this.getAttributeListByPartsId(this.id)
		},
		methods: {
			// 图片预览
			previewImage(item, index){
				console.log(item);
				let lis = item.split()
				wx.previewImage({
				  current: 0, // 当前显示图片的http链接
				  urls: lis // 需要预览的图片http链接列表
				})
			},
			// 跳转到编辑型号
			cli_edit (item) {
				let id = item.id
				let attributeLogo = item.attributeLogo
				let attributeName = item.attributeName
				let attributeSalePrice = item.attributeSalePrice
				let attributeStock = item.attributeStock
				let attributeRemarks = item.attributeRemarks
				let isPost = item.isPost
				
				uni.navigateTo({
					// url: '/pages/shopModelEdit/shopModelEdit?id=' + id
					url: `/pages/shopModelEdit/shopModelEdit?id=${id}&attributeLogo=${attributeLogo}&attributeName=${attributeName}&attributeSalePrice=${attributeSalePrice}&attributeStock=${attributeStock}&attributeRemarks=${attributeRemarks}&isPost=${isPost}`
				})
			},
			// 点击上下架
			cli_j (item) {
				console.log(111);
				let isShow
				let id = item.id
				let _that = this
				if (item.isShow == 1) {
					isShow = 0
				}else {
					isShow =1
				}
				uni.request({
					url: allapi.updateAttributeIsShow,
					data: {
						id: id,
						isShow: isShow
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						_that.getAttributeListByPartsId (this.id)
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			// 查看全部型号
			getAttributeListByPartsId(id) {
				uni.request({
					url: allapi.getAttributeListByPartsId,
					data: {
						id: id
					},
					success: (res) => {
						console.log(res);
						this.list = res.data.data
					}
				})
			}
		}
	}
</script>

<style scoped>
	.shopModelAll-list {
		margin: 0 24rpx;
	}
		

	.shopModelAll-li {
		margin: 16rpx 0;
		padding: 24rpx;
		display: flex;
		background: #FFFFFF;
		border-radius: 16rpx;
	}

	.shopModelAll-li-left {}

	.shopModelAll-li-left-img {
		width: 184rpx;
		height: 184rpx;
		border-radius: 8rpx;
	}

	.shopModelAll-li-right {
		height: 184rpx;
		margin-left: 40rpx;
		flex: 1;
	}

	.shopModelAll-li-right-title {
		margin-top: 16rpx;
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
	}

	.shopModelAll-li-right-id {

		font-size: 24rpx;
		color: #999999;
		font-weight: 400;
		line-height: 32rpx;
		margin-top: 16rpx;
	}

	.shopModelAll-li-right-btm {
		margin-top: 16rpx;
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
	}

	.shopModelAll-li-right-btm-left {
		display: flex;
		align-items: center;
	}

	.shopModelAll-li-right-btm-left-txt1 {
		font-size: 24rpx;
		color: #EF691C;
		font-weight: 400;
	}

	.shopModelAll-li-right-btm-left-txt2 {
		font-size: 36rpx;
		color: #EF691C;
	}

	.shopModelAll-li-right-btm-left-txt3 {
		font-size: 28rpx;
		color: #333333;
		font-weight: 400;
	}

	.shopModelAll-li-right-btm-right {
		display: flex;
		justify-content: flex-end;
	}

	.shopModelAll-li-right-btm-right-bj {
		width: 92rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		border-radius: 27rpx;
		border: 2rpx solid #333333;
		font-size: 20rpx;
		color: #333333;
		margin-right: 24rpx;
	}

	.shopModelAll-li-right-btm-right-ljsj {
		width: 132rpx;
		height: 54rpx;
		line-height: 54rpx;
		text-align: center;
		background: linear-gradient(90deg, #2ACE52 0%, #1DC248 100%);
		border-radius: 27rpx;
		font-size: 20rpx;
		color: #FFFFFF;
	}
</style>
